home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
LANG
/
C
/
LIB
/
UNIXLIB37B
/
!UnixLib37
/
src
/
pwd
/
c
/
pwdread
< prev
Wrap
Text File
|
1996-11-09
|
2KB
|
96 lines
/****************************************************************************
*
* $Source: /unixb/home/unixlib/source/unixlib37/src/pwd/c/RCS/pwdread,v $
* $Date: 1996/10/30 22:04:51 $
* $Revision: 1.1 $
* $State: Rel $
* $Author: unixlib $
*
* $Log: pwdread,v $
* Revision 1.1 1996/10/30 22:04:51 unixlib
* Initial revision
*
***************************************************************************/
static const char rcs_id[] = "$Id: pwdread,v 1.1 1996/10/30 22:04:51 unixlib Rel $";
/* pwd.c.pwdread. Internal password-file reading functions.
Modified from the original c.getpw by Nick Burrett, 13 October 1996. */
#include <errno.h>
#include <limits.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <pwd.h>
/* p_pstrcp() */
static char *
p_pstrcp (char **lp)
{
register char *l = *lp, *r = l;
while ((*l != ':') && *l)
l++;
if (*l)
*l++ = 0;
*lp = l;
return (r);
}
/* p_pdecode() */
static void
p_pdecode (char *line, struct passwd *passwd)
{
char *lp;
if (!line || !passwd)
return;
lp = line;
passwd->pw_name = p_pstrcp (&lp);
passwd->pw_passwd = p_pstrcp (&lp);
passwd->pw_uid = atoi (p_pstrcp (&lp));
passwd->pw_gid = atoi (p_pstrcp (&lp));
passwd->pw_gecos = p_pstrcp (&lp);
passwd->pw_dir = p_pstrcp (&lp);
passwd->pw_shell = p_pstrcp (&lp);
}
/* Read one entry from the given stream. */
struct passwd *
__pwdread (FILE *stream, struct passwd *ppwd)
{
char buf[256], *bp;
if (stream == NULL)
return 0;
/* Get a line, skipping past comment lines. */
do
if (fgets (buf, sizeof (buf) - 1, stream) == 0)
/* if (getline (buf, sizeof (buf) - 1, stream) == -1) */
return 0;
while (buf[0] == '#');
/* Take the line and convert the newline into a zero terminated
string. */
bp = buf;
while (*bp)
bp++;
if (*--bp != '\n')
return 0;
*bp = 0;
/* Decode the line. */
p_pdecode (buf, ppwd);
return ppwd;
}